package com.ermace.robo.jumper.game;

import com.ermace.robo.jumper.R;
import com.ermace.robo.jumper.game.Map;
import com.ermace.robo.jumper.game.GameObjects.GameObject;
import com.ermace.robo.jumper.game.GameObjects.Ice;
import com.ermace.robo.jumper.game.GameObjects.Rectangle;

public enum MapList {
	
	OLD_CITY(R.drawable.old_city, "Old City", R.drawable.old_city, R.drawable.old_city_title,
			new Rectangle(12, 15, 6, R.drawable.metal_bar),
			new Rectangle(3, 10, 6, R.drawable.metal_bar),
			new Rectangle(21, 10, 6, R.drawable.metal_bar),
			new Rectangle(12, 5, 6, R.drawable.metal_bar)),
			
	SNOW_LAND(R.drawable.ice_landscape, "Snowland", R.drawable.ice_landscape, R.drawable.snow_land_title,
			new Ice(3, 15, 6, R.drawable.snow_platform),
			new Ice(21, 15, 6, R.drawable.snow_platform),
			new Ice(10, 7, 10, R.drawable.snow_platform)),
			
	SPACE(R.drawable.star, "Space", R.drawable.star, R.drawable.snow_land_title,
			new Rectangle(3, 7, 6, R.drawable.asteroid_block),
			new Rectangle(21, 7, 6, R.drawable.asteroid_block),
			new Rectangle(9, 15, 12, R.drawable.asteroid_block)),
	
	LAVA_LAND(R.drawable.lava_landscape, "Lavaland", R.drawable.lava_landscape, R.drawable.snow_land_title,
			new Rectangle(3, 7, 6, R.drawable.lava_block),
			new Rectangle(21, 7, 6, R.drawable.lava_block),
			new Rectangle(9, 15, 12, R.drawable.lava_block));
	
	/**
	 * 
	 * @param mapName	The name of the map.
	 * @return	The map with the given name or null
	 * 			if there is no such map.
	 */
	public static Map getMapByName(String mapName) {
		for(MapList map: MapList.values())
			if (map.mapName.equals(mapName))
				return map.getMap();
		
		return null;
	}
	
	private int imageId;
	private String mapName;
	private int backgroundId;
	private int titleId;
	private boolean unlocked;
	private GameObject[] objects;

	private MapList(int imgId, String mapName, int bgId, int titleId, boolean unlocked, GameObject... objects) {
		imageId = imgId;
		this.mapName = mapName;
		backgroundId = bgId;
		this.titleId = titleId;
		this.unlocked = unlocked;
		this.objects = objects;
	}
	
	private MapList(int imgId, String mapName, int bgId, int titleId, GameObject... objects) {
		this(imgId, mapName, bgId, titleId, true, objects);
	}
	
	public void setUnlocked() {
		unlocked = true;
	}
	
	public Map getMap() {
		Map map = new Map(imageId, mapName, backgroundId, titleId, unlocked);
		for (GameObject obj: objects)
			map.addObject(obj);
		
		return map;
	}
}
